//Armored Unit - //create by spectre100, modified by Spam_One--------------------------------------------------------------


//modified by Spam_One -> probability for sidemission, because Armored and Air vehicles could fuck the gameplay when too much

_proba = random 100;
if (_proba < 15) then {
	diag_log " Missions 6 launched";
	private ["_rad","_cnps","_hills","_hillcount","_hillnum","_hill","_marker","_checking","_people","_hillpos"];
	
	sleep 300;
		
	[player,nil,rSIDECHAT,"An armored unit has been located. Find it before they find you with it !"] call RE;
	[nil,nil,rHINT,"An armored unit has been located. Find it before they find you with it !"] call RE;
	private ["_rad","_cnps","_hills","_hillcount","_hillnum","_hill","_marker"];
	
	_rad=20000;
	_cnps = getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition");
	_hills = nearestLocations [_cnps, ["FlatArea"], _rad];
	_hillcount = count _hills;
	_hillnum = floor (random _hillcount);
	_hill = _hills select _hillnum;
	_hillpos = getpos _hill;
	
	_marker_name = STR_MISSION_MARKER_1 + str (serverTime);
	_marker = "";
	if (CVG_sideMarkers == 0) then {
		
		_marker = createMarker [_marker_name,_hillpos];
		_marker setMarkerType "mil_destroy";
		_marker setMarkerColor "ColorOrange";
		_marker setMarkerText "Armored Unit";
		_marker setMarkerSize [1,1];
	};
	
	if (CVG_sideMarkers == 1) then {
		_hillpos = [(_hillpos select 0) + random 100, (_hillpos select 1) + random 100,0];
		_marker = createMarker [_marker_name,_hillpos];
		_marker setMarkerShape "ellipse";
		_marker setMarkerBrush "DiagGrid";
		_marker setMarkerColor "ColorOrange";
		_marker setMarkerText "Armored Unit";
		_marker setMarkerSize [350,350];
	};
	
	missionActive = true;
	missionVars = [_marker_name,_hillpos];
	publicVariable "missionActive";
	publicVariable "missionVars";
	
	_truckArray = ["BMP2_CDF","T34","M113_UN_EP1","M6_EP1","T34_TK_GUE_EP1","T55_TK_EP1"];;
	_chosen = _truckArray call BIS_fnc_selectRandom;
	TRUCK = createVehicle [_chosen,[(getpos _hill select 0) + (floor random 50), (getpos _hill select 1) + (floor random 50), 0],[], 0, "NONE"];
	TRUCK setVehicleVarName _chosen;
	TRUCK setFuel (random .6);
	TRUCK setDamage (random .9);
	TRUCK setVehicleAmmo (random .4);
	
	_checking = 1;
	while {_checking == 1} do {
		_people =  nearestObjects [[getpos TRUCK select 0, getpos TRUCK select 1,0],["LandVehicle","Man"],50];
		if ({isPlayer _x} count _people > 0) then {_checking = 0};
		sleep 1;
	};
	
	[player,nil,rSIDECHAT,"Armored unit found. Stay far from mines and rockets !"] call RE;
	[nil,nil,rHINT,"Chopper found. Stay far from AA !"] call RE;
	_marker setMarkerColor "ColorBlue";
	
	missionActive = false;
	publicVariable "missionActive";
	deleteMarker _marker;
	
	// hordes // Spam_One -------------------------------------------------------------------------
	
	// putting a unit which we can rotate for finding a safe pos and randomize where hordes come from
	
	// first Horde --------------------------------------------------------------------------------
	_position = [TRUCK, 50, 50 , 75] call WF_FNCT_getRandomSafePos;
	trigger = createTrigger ["EmptyDetector", _position];
	trigger setTriggerArea [10, 10, 0, false];
	
	[trigger,30,CLY_hordetrigger,"normal"] execVM "zombie_scripts\cly_z_horde.sqf"; // horde exec
	hint "first horde spawned";
	sleep 20;
	
	// second Horde -------------------------------------------------------------------------------
	_position = [TRUCK, 50, 50 , 75] call WF_FNCT_getRandomSafePos;
	trigger2 = createTrigger ["EmptyDetector", _position];
	trigger2 setTriggerArea [10,10,0,false];
	
	[trigger2,30,CLY_hordetrigger,"normal"] execVM "zombie_scripts\cly_z_horde.sqf"; // horde exec
	
	hint "second horde spawned";
	sleep 20;
	
	// End of hordes ------------------------------------------------------------------------------
	
	deleteVehicle _safePos;
	
	SM1=6;
	[0] execVM "sideMissions\SMfinder.sqf";
} else {
    [] execVM "sideMissions\SMfinder.sqf";
}